package com.module.circle.ui.circleMembersList

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.common.app.data.bean.circle.CircleDetailMemberListBean
import com.common.app.data.bean.circle.CirclesRankMyRankingBean
import com.common.app.helper.UserHelper
import com.common.app.utls.TimeUtils
import com.common.app.utls.TimeUtils.formatTime2
import com.common.app.utls.TimeUtils.getTimeDateLong
import com.common.base.app.extras.loadRound
import com.common.base.app.extras.otherwise
import com.common.base.app.extras.yes
import com.common.base.utils.ViewUtils.getColor
import com.common.base.utils.ViewUtils.getDrawable
import com.common.base.utils.ViewUtils.getString
import com.module.circle.R

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2025/07/24
 *
 * 描述：
 *
 * 修订历史：
 *
 */
open class MembersListItemAdapter(isLeader: Boolean = false) : BaseQuickAdapter<CircleDetailMemberListBean, BaseViewHolder>(R.layout.circle_item_menbers_list_layout) {

    var showDelBtn = false
    init {
        addChildClickViewIds(R.id.totalRoot)
        addChildClickViewIds(R.id.tvDelBtn)

        showDelBtn = isLeader
    }

    override fun convert(holder: BaseViewHolder, item: CircleDetailMemberListBean) {
        holder.getView<ImageView>(R.id.picImg).loadRound(item.avatar_url, 100)
        holder.setText(R.id.tvName, item.nickname)
        holder.setText(R.id.tvNote, item.description)
        holder.setGone(R.id.imgSex, item.sex < 0)
        holder.getView<ImageView>(R.id.imgSex).setImageDrawable(when(item.sex){
            0-> getDrawable(R.drawable.circle_circle_sex_female_icon)
            1-> getDrawable(R.drawable.circle_circle_sex_male_icon)
            else-> null
        })
        holder.setText(R.id.tvMedalNum, "${item.badge_count}${getString(R.string.circle_splicing_medal_hint)}")

        holder.setGone(R.id.tvCommanderMark, !item.is_leader)

        item.is_online.yes {
            holder.setText(R.id.tvOnTime, R.string.common_online_hint)
            holder.setTextColor(R.id.tvOnTime, getColor(R.color.c_6a98f4))
            holder.setBackgroundResource(R.id.tvOnTime, R.drawable.bg_round_e5eeff_100)
        }.otherwise {
            holder.setTextColor(R.id.tvOnTime, getColor(R.color.c_7f7f7f))
            holder.setBackgroundResource(R.id.tvOnTime, R.drawable.bg_round_ebebeb_100)
            (item.last_online <=0).yes {
                holder.setText(R.id.tvOnTime, R.string.circle_two_years_ago_hint)
            }.otherwise {
                //时间差
                val timeDifference = getTimeDateLong() - (item.last_online * 1000)
                holder.setText(R.id.tvOnTime, "${formatTime2(timeDifference)}${getString(R.string.common_ago_splicing_hint)}")
            }
        }

        showDelBtn.yes {
            holder.setGone(R.id.tvDelBtn, item.is_leader)
        }.otherwise {
            holder.setGone(R.id.tvDelBtn, true)
        }
    }
}